//
//  MyContactListener.cpp
//  fingeradvanture
//
//  Created by 8089 on 16/5/8.
//
//

#include "MyContactListener.h"

void MyContactListener::BeginContact(b2Contact* contact)
{
    //log("BeginContact");
    
    
    b2Body* bodyA = contact->GetFixtureA()->GetBody();
    b2Body* bodyB = contact->GetFixtureB()->GetBody();
    auto spriteA = (Sprite*)bodyA->GetUserData();
    auto spriteB = (Sprite*)bodyB->GetUserData();
    
    if (spriteA != nullptr && spriteB != nullptr)
    {
        spriteA->setColor(Color3B::YELLOW);
        spriteB->setColor(Color3B::YELLOW);
    }
}


void MyContactListener::EndContact(b2Contact* contact)
{
    //log("EndContact");
    
    
    b2Body* bodyA = contact->GetFixtureA()->GetBody();
    b2Body* bodyB = contact->GetFixtureB()->GetBody();
    auto spriteA = (Sprite*)bodyA->GetUserData();
    auto spriteB = (Sprite*)bodyB->GetUserData();
    
    if (spriteA != nullptr && spriteB != nullptr)
    {
        spriteA->setColor(Color3B::WHITE);
        spriteB->setColor(Color3B::WHITE);
    }
}


void MyContactListener::PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
{
    //log("PreSolve");
}


void MyContactListener::PostSolve(b2Contact* contact, const b2ContactImpulse* impulse)
{
    //log("PostSolve");
}